package com.ku.test;

import com.ku.log.entity.Operator;
import com.ku.log.facade.OperatorAvailable;
import com.ku.test.service.UserService;
import com.ku.test.service.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @author: GZQ
 * @create: 2020/08/09
 * @description: 实例化 OperatorAvailable接口
 **/
@Slf4j
@Component
@Configuration
public class OperatorConfig {

    @Autowired
    private UserService userService;

    @Bean
    public OperatorAvailable operatorAvailable () {
        return token -> {
            log.info("获取当前操作人信息");
            User user = userService.queryUserInfo();
            if (user == null) {
                return null;
            }
            return Operator.builder().token(token).loginName(user.getLoginName())
                    .operatorId(String.valueOf(user.getId())).operatorName(user.getName()).build();
        };
    }
}
